<?php
    
    header('Content-type: text/html; charset=utf-8');
    error_reporting(E_ALL); 
    date_default_timezone_set("Asia/Saigon");
    require_once("config.php");     
    require_once("functions.php");     
    
    $username = "vintelcom_8x55";
    $password = "IdgGSaR8xqOTm35";
    $date = date("Y-m-d",time());
   
    $key=md5($username.$date.md5($password));
    $url = "http://ws.report.gomobi.vn/?control=get_card&service=get_date_card&username=".$username."&date=".$date."&token=".$key;
    $json=cUrl($url);
    $arr =json_decode($json,true) ;
    //var_dump($arr)  ; die;
    $arr_values = array();
    $arr_key = array("transactionId","userId","partnerId","type","appID","provider_code","card_code","card_seri","price","charg_status","status","requested_date","responsed_date","day","month","year","create_date","percent_wapmaster","percent_partner");
    if(!isset($arr['error']) && !isset($arr['error_code'])) { 
        foreach($arr as $value){
            if($value['card_type']=="vms"){
                 $provider_code ="VMS";
            }else if($value['card_type']=="vina"){
                  $provider_code ="VNP"; 
            }else if($value['card_type']=="viettel") {
                  $provider_code = "VTT";
            }
            if($value['provider']==486){
                 $appID =11;
            }else if($value['provider']==158){
                  $appID =4; 
            }else if($value['provider']==133){
                  $appID =5; 
            }else if($value['provider']==236){
                  $appID =8; 
            }else if($value['provider']==52){
                  $appID =10; 
            }
            $day = intval(date('d',strtotime($value['logdate'])));
            $month = intval(date('m',strtotime($value['logdate'])));
            $year = intval(date('Y',strtotime($value['logdate'])));
            $userInfo = getUserIdByRefCode($value['refcode']);     
            $gameInfo = getGameInfo($appID);     
            //var_dump($gameInfo,$day,$month,$year) ;die;
            $arr_values[]=array("",$userInfo['id'],"55","1",$appID,$provider_code,"","",$value['menh_gia'],2,1,strtotime($value['logdate']),strtotime($value['logdate']),$day,$month,$year,time(),$gameInfo['percent_wapmaster'],$gameInfo['percent_partner']);  
        }
        $curDay = intval(date("d",time()));
        $curMonth = intval(date("m",time()));
        $curYear = intval(date("Y",time()));
        
        $del = deleteCardMeCorpByDate($curDay,$curMonth,$curYear);
        $result = insertManyRows("c_card_log",$arr_key,$arr_values) ;
        if ($result > 0){
            echo "Cron Job success at ".date("Y-m-d",time());
        }
    }else{
        echo isset($arr['message'])? $arr['message'] : $arr['msg'];       
    }
?>
